package com.yaoge.after.aspect;

import com.yaoge.after.service.Price;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

import java.lang.reflect.Field;

//用@Aspect来表明这是一个切面类，让AspectJ能够找到这个切面类
@Aspect
public class SellAspect {
    @AfterReturning(value = "execution(* com.yaoge.after.service.*.Sell(..) )",returning="result")
    public  void sellAdvance(Object result) throws NoSuchFieldException, IllegalAccessException {
        System.out.println("在业务执行之后进行操作");
        String s=new String("lalallala，数据被我更改了");
        result=(String)result;
        Field field= result.getClass().getDeclaredField("value");
        field.setAccessible(true);
        field.set(result,new char[]{'a','a','a'});


        System.out.println("返回执行结果+1"+result);

    }
    @AfterReturning(value = "execution(* com.yaoge.after.service.*.Sell1(..) )",returning="result")
    public  void sell1Advance(Object result){
        System.out.println("在业务执行之后进行操作");
        Price p=(Price) result;
        p.setS(200000);
        result=p;

    }
}
